// 维护用户状态数据
import { reactive, ref } from 'vue'

// 1. 定义类型

type UserInfo = {
  name: string
  mobile: string
}

// 2. 响应式数据
let userInfo: UserInfo = reactive({
  name: '',
  mobile: ''
})
const token = ref<string>('')
// 3. 修改数据的方法
const setUserInfo = (newUserInfo: UserInfo) => {
  /*   const { name, mobile } = newUserInfo
  userInfo.name = name
  userInfo.mobile = mobile */
  // userInfo = newUserInfo  不能这么做
  userInfo = Object.assign(userInfo, newUserInfo)
}
const setToken = (newToken: string) => {
  token.value = newToken
}
export { userInfo, setUserInfo, token, setToken }
